import unittest
import requests
from python接口测试.FIC_项目代号.api_测试接口.LaoHuangLi import LaoHuangLi

class testLaoHuangLi01(unittest.TestCase):

    def setUp(self) -> None:
        self.LaoHuangLi = LaoHuangLi()
        self.session = requests.Session()

    def tearDown(self) -> None:
        if self.session:
            self.session.close()



    """
    http://v.juhe.cn/laohuangli/d?key=2b1e89319e5d888a525a421ea57ba3c5&date=2022-11-11
    """

    # 查询老黄历成功
    def test01_getLaohuangli_success(self):
        response = self.LaoHuangLi.getLaoHuangLi(self.session,"2b1e89319e5d888a525a421ea57ba3c5","2022-11-11")
        # print(response.json())
        """
        用途：断言
            实现：
            response.status_code :响应状态码
            response.url :url地址信息
            response.encoding :查看响应数据编码格式
            response.headers ：查看头部信息
            response.cookies : 查看cookies信息
            response.text :文本形式查看响应数据
            response.content ：字节码形式查看响应数据
            response.json() ：json形式查看响应数据
        """
        self.assertEqual(200,response.status_code)
        self.assertEqual("successed",response.json().get("reason"))
        # print(response.json().get("result").get("yangli"))
        self.assertIn('2022-11-11',response.json().get("result").get("yangli"))



    # 错误的请求key
    def test02_getLaohuangli_error_key(self):
        response = self.LaoHuangLi.getLaoHuangLi(self.session, "error_key", "2022-11-11")
        # print(response.json())
        self.assertEqual(10001,response.json().get("error_code"))
        self.assertIn("错误的请求KEY",response.json().get("reason"))

    # 日期不能为空
    def test03_getLaohuangli_data_cannot_null(self):
        response = self.LaoHuangLi.getLaoHuangLi(self.session, "2b1e89319e5d888a525a421ea57ba3c5", "")
        # print(response.json())
        self.assertEqual(206501,response.json().get("error_code"))
        self.assertIn("日志不能为空",response.json().get("reason"))

